package fr.noe.amicaleloisirs.concours.view;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;

public class InfoPopUp extends PopupPanel  {

	/**
	 * Créé et affiche une PopUp d'info.
	 *
	 * @param text: le texte à afficher.
	 * @param handler: un click handler permettant de définir un traitement particulier lors du click.
	 */
	public InfoPopUp(final String text, final ClickHandler handler) {
		setGlassEnabled(true);
		setModal(true);
		setSize("300px", "200px");

		VerticalPanel verticalPanel = new VerticalPanel();
		verticalPanel.setSpacing(10);
		verticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		setWidget(verticalPanel);
		verticalPanel.setSize("100%", "100%");

		Label lblNewLabel = new Label(text);
		lblNewLabel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		verticalPanel.add(lblNewLabel);
		verticalPanel.setCellHorizontalAlignment(lblNewLabel, HasHorizontalAlignment.ALIGN_CENTER);
		verticalPanel.setCellVerticalAlignment(lblNewLabel, HasVerticalAlignment.ALIGN_MIDDLE);
		lblNewLabel.setSize("100%", "80%");

		Button btnNewButton = new Button("OK");
		btnNewButton.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				handler.onClick(event);
				InfoPopUp.this.hide();
			}
		});
		verticalPanel.add(btnNewButton);
		this.center();
	}

}
